<template>
  <div class="ze-tabbar" :style="tabbarStyle">
    <div
      v-for="item in items" :key="item.name" class="tabbar-item"
      :class="{active: active === item.name}"
      @click="$emit('change', item.name)"
    >
      <image class="icon" :src="`${active===item.name ? item.activeIcon : item.inactiveIcon}`" />
      <div class="title">
        {{ item.title }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    color: {
      type: String,
      default: '#CCCCCC',
    },
    activeColor: {
      type: String,
      default: '#739ECA',
    },
    background: {
      type: String,
      default: '#ffffff',
    },
    items: {
      type: Array,
      required: true,
    },
    active: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
    }
  },
  computed: {
    tabbarStyle() {
      return `
        background: ${this.background};
        --ze-tabbar-color: ${this.color};
        --ze-tabbar-active-color: ${this.activeColor};
      `
    },
  },
}
</script>

<style lang="scss" scoped>
.ze-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50px;
  padding-bottom:env(safe-area-inset-bottom);
  display: flex;
  box-shadow: 0 -1px 6px rgba(0, 0, 0, .1);

  .tabbar-item {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--ze-tabbar-color);

    &.active {
      color: var(--ze-tabbar-active-color);
    }

    .icon {
      width: 30px;
      height: 30px;
    }
    .title {
      margin-top: 3px;
      font-size: 11px;
      line-height: 12px;
    }
  }
}
</style>
